<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{       
    protected function _initAutoload()
    {
        $loader = new Zend_Application_Module_Autoloader(array(
            'namespace' => '',
            'basePath' => APPLICATION_PATH .'/'
            ));
        $loader->initDefaultResourceTypes();    
		$helper = new Common_Controller_Action_Helper_Acl();
		$helper->setRoles();
		$helper->setResources();
		$helper->setPrivilages();
		$helper->setAcl();
		//Zend_Controller_Action_HelperBroker::addHelper($helper);
		$front = Zend_Controller_Front::getInstance();
		$front->registerPlugin(new Common_Plugin_Acl()); 
        return $loader;
    }
    protected function _initDoctrine()
    {
        $this->getApplication()->getAutoloader()
                               ->pushAutoloader(array('Doctrine', 'autoload'));
        $this->getApplication()->getAutoloader()->setFallbackAutoloader(true);
        $manager = Doctrine_Manager::getInstance();
        $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
        $manager->setAttribute(
            Doctrine::ATTR_MODEL_LOADING, 
            Doctrine::MODEL_LOADING_AGGRESSIVE
        );
        $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);

        $doctrine_options = $this->getOption('doctrine');
        
        $dsn = $doctrine_options['dsn'];
        $conn = Doctrine_Manager::connection($dsn, 'doctrine');
        $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
        
        Zend_Registry::set('doctrine_config', array(
            'data_fixtures_path'  =>  APPLICATION_PATH . '/doctrine/data/fixtures',
            'models_path'         =>  APPLICATION_PATH . '/models',
            'migrations_path'     =>  APPLICATION_PATH . '/doctrine/migrations',
            'sql_path'            =>  APPLICATION_PATH . '/doctrine/data/sql',
            'yaml_schema_path'    =>  APPLICATION_PATH . '/doctrine/schema',
            "generate_models_options" => array(
            'generateBaseClasses'   =>  true,
            'generateTableClasses'  =>  true,
            'generateAccessors'     =>  true,
            'classPrefixFiles'      =>  false,
            'classPrefix'           =>  'Default_Model_',
            'baseClassesDirectory'  =>  'base',
            /*'baseClassPrefixFiles'  =>  false,
            'baseClassPrefix'       => 'Base_',*/
            'baseClassName'         =>  'Doctrine_Record'
        )));
        
        return $conn;
    }
    protected function _initLayoutHelper()
    {
            $helper = new Common_Controller_Action_Helper_ModuleSetup();
            $layout = Zend_Controller_Action_HelperBroker::addHelper($helper);
            
            $profiler = new Doctrine_Connection_Profiler();
            $conn = Doctrine_Manager::connection();
            $conn->setListener($profiler);
    }
    
    protected function _initViewHelper()
    {
            $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
            $viewRenderer->initView();
            $viewRenderer->view->addHelperPath(APPLICATION_PATH . '/views/helpers');
    }
    
    public function _initSession()
    {
        //$instance = CONFIG_SERVER_TYPE;
//        if (!empty($_COOKIE[$instance]['sessid'])) {
//            Zend_Session::setId($_COOKIE[$instance]['sessid']);
//        }
        $session = new Zend_Session_Namespace('Zend_Auth');
    }
}
